package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorConfig;
import com.yanqu.road.entity.activity.peakstronghold.CrossPeakStrongholdUnionData;
import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongholdBaseConfig;
import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongholdDonateConfig;
import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongholdTimeConfig;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.pb.commonactivity.CommonActivityProto;
import com.yanqu.road.server.logic.activity.stronghold.StrongholdActivityData;

import java.util.List;
import java.util.Map;

public class PeakStrongholdActivityWarPb {

    public static PeakStrongholdWarProto.SyncPeakStrongholaActivityMsg.Builder
    getPeakStrongholdActivityMsg(Map<Integer, HuaShiGangFloorConfig> desertConfigMap,
                                 Map<Integer, PeakStrongholdDonateConfig> donateConfigMap,
                                 Map<Integer, PeakStrongholdBaseConfig> baseConfigMap,
                                 Map<Integer, PeakStrongholdTimeConfig> timeConfigMap,
                                 String language) {
        PeakStrongholdWarProto.SyncPeakStrongholaActivityMsg.Builder syncMsg = PeakStrongholdWarProto.SyncPeakStrongholaActivityMsg.newBuilder();
        PeakStrongholdWarProto.PeakStrongholdActivityMsg.Builder msg = PeakStrongholdWarProto.PeakStrongholdActivityMsg.newBuilder();
        for (HuaShiGangFloorConfig desertConfig : desertConfigMap.values()) {
            msg.addDesertFloor(parseDesertFloorTempMsg(desertConfig));
        }
        for (PeakStrongholdTimeConfig timeConfig : timeConfigMap.values()) {
            msg.addTimeInfo(parseTimeConfigTempMsg(timeConfig));
        }
        for (PeakStrongholdBaseConfig baseConfig : baseConfigMap.values()) {
            msg.addBaseInfo(parseBaseTempMsg(baseConfig));
        }
        for (PeakStrongholdDonateConfig donateConfig : donateConfigMap.values()) {
            msg.addDonateInfo(parseDonateTempMsg(donateConfig));
        }
        syncMsg.setMsg(msg);
        return syncMsg;
    }


    private static PeakStrongholdWarProto.PeakStrongholdBaseTempMsg.Builder parseBaseTempMsg(PeakStrongholdBaseConfig donateConfig) {
        PeakStrongholdWarProto.PeakStrongholdBaseTempMsg.Builder msg = PeakStrongholdWarProto.PeakStrongholdBaseTempMsg.newBuilder();
        msg.setLevel(donateConfig.getLevel());
        msg.setIcon(donateConfig.getIcon());
        msg.setHpAdd(donateConfig.getHpAdd());
        msg.setNeedProcess(donateConfig.getNeedProcess());
        return msg;
    }

    private static PeakStrongholdWarProto.PeakStrongholdDonateTempMsg.Builder parseDonateTempMsg(PeakStrongholdDonateConfig donateConfig) {
        PeakStrongholdWarProto.PeakStrongholdDonateTempMsg.Builder msg = PeakStrongholdWarProto.PeakStrongholdDonateTempMsg.newBuilder();
        msg.setId(donateConfig.getId());
        msg.setConsume(donateConfig.getConsume());
        msg.setExp(donateConfig.getExp());
        msg.setMaxNum(donateConfig.getMaxNum());
        msg.setRewards(Integer.valueOf(donateConfig.getRewards()));
        return msg;
    }

    private static PeakStrongholdWarProto.PeakStrongholdTimeTempMsg.Builder parseTimeConfigTempMsg(PeakStrongholdTimeConfig timeConfig) {
        PeakStrongholdWarProto.PeakStrongholdTimeTempMsg.Builder msg = PeakStrongholdWarProto.PeakStrongholdTimeTempMsg.newBuilder();
        msg.setTimeId(timeConfig.getTimeId());
        msg.setType(timeConfig.getType());
        msg.setBeginTime(timeConfig.getBeginTime());
        msg.setDurationTime(timeConfig.getDurationTime());
        msg.setParam(timeConfig.getParam());
        msg.setScore(timeConfig.getScore());
        return msg;
    }

    private static PeakStrongholdWarProto.PeakStrongholdDesertFloorTempMsg.Builder parseDesertFloorTempMsg(HuaShiGangFloorConfig config) {
        PeakStrongholdWarProto.PeakStrongholdDesertFloorTempMsg.Builder msg = PeakStrongholdWarProto.PeakStrongholdDesertFloorTempMsg.newBuilder();
        msg.setFloor(config.getFloor());
        msg.setSpecialReward(config.getSpecialReward());
        msg.setRewards(config.getRewards());
        msg.setConsume(config.getConsume());
        return msg;
    }

    public static CommonActivityProto.CommonActivityDataMsg.Builder parseCommonActivityDataMsg(StrongholdActivityData activityData) {
        if (null == activityData) {
            return null;
        }
        CommonActivityProto.CommonActivityDataMsg.Builder msg = CommonActivityProto.CommonActivityDataMsg.newBuilder();
        for (UserActivityConditionData conditionData : activityData.getUserActivityConditionDataList()) {
            CommonActivityProto.CommonActivityConditionDataMsg.Builder conditionDataMsg = CommonActivityPb.parseCommonActivityConditionDataMsg(conditionData);
            if (null != conditionDataMsg) {
                msg.addConditionDataList(conditionDataMsg);
            }
        }
        return msg;
    }
}
